import { familyTree } from "@/util/index";
const setting = {
    state: {
        isCollapse: false,
        nav: [],
        breadcrumb: [],
        menuActive: '',
        menuList: [],
    },
    mutations: {
        getMenuList(state:any, newState:any){
            state.menuList = newState.menuList;
        },
        getCollapse(state: any, newState: any) {
            state.isCollapse = newState.isCollapse;
        },
        getNav(state: any, newState: any) {
            if (state.nav.length > 0) {
                let i = -1;
                state.nav.forEach((element: any, index: number) => {
                    if (element.id == newState.nav.id) {
                        i = index;
                    }
                });
                if (i == -1) {
                    state.nav.push(newState.nav);
                }
            } else {
                state.nav.push(newState.nav);
            }
        },
        getMenuActive(state: any, newState: any) {
            state.breadcrumb = familyTree(state.menuList, newState.menuActive);
            state.menuActive = newState.menuActive;
        },
    },
    actions: {
        setMenuList(context:any, newState:any) {
            context.commit('getMenuList', newState)
        },
        setCollapse(context: any, newState: any) {
            context.commit('getCollapse', newState)
        },
        setNav(context: any, newState: any) {
            context.commit('getNav', newState)
        },
        setMenuActive(context: any, newState: any) {
            context.commit('getMenuActive', newState)
        },
    }
};
export default setting;